package com.paomi.client.activity.person;

import android.content.Intent;
import android.support.annotation.NonNull;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.widget.TextView;

import com.paomi.client.R;
import com.paomi.client.activity.main.MainActivity;
import com.paomi.client.activity.person.Adapter.MyPointAdapter;
import com.paomi.client.activity.person.View.MyPointView;
import com.paomi.client.activity.person.model.GetBalanceBean;
import com.paomi.client.activity.person.model.TaskListBean;
import com.paomi.client.activity.person.model.TaskListDetailBean;
import com.paomi.client.activity.person.presenter.MyPointPre;
import com.paomi.client.base.BaseMvpActivity;
import com.paomi.client.utils.Util;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.OnClick;

public class MyPointActivity extends BaseMvpActivity<MyPointView, MyPointPre> implements MyPointView {
    @BindView(R.id.button_goback)
    TextView button_goback;
    @BindView(R.id.tv_record)
    TextView tv_record;
    @BindView(R.id.tv_point)
    TextView tv_point;

    @BindView(R.id.recyclerView)
    RecyclerView recyclerView;

    List<TaskListDetailBean> lists = new ArrayList<>();

    MyPointAdapter adapter;

    @Override
    protected String setTitle() {
        return getResources().getString(R.string.my_points);
    }

    @Override
    protected void showBack(TextView button_goback) {
        button_goback.setVisibility(View.VISIBLE);
    }

    @NonNull
    @Override
    protected int getLayoutId() {
        return R.layout.activity_my_point;
    }

    @Override
    protected void initEvent() {
        button_goback.setTypeface(iconfont);
        button_goback.setCompoundDrawablesWithIntrinsicBounds(0, 0, 0, 0);
        button_goback.setTextColor(getResources().getColor(R.color.main_color));
        button_goback.setText(getResources().getString(R.string.back_normal) + getResources().getString(R.string.back));

        adapter = new MyPointAdapter(this);
        recyclerView.setLayoutManager(new LinearLayoutManager(this));
        recyclerView.setAdapter(adapter);
        adapter.setOnItemClick(new MyPointAdapter.onItemClickListener() {
            @Override
            public void OnItemClick(View view, int position) {
                TaskListDetailBean bean=lists.get(position);
                switch (bean.getKey()){
                    case "COMMENTS"://评论
                        startActivity(new Intent(MyPointActivity.this, MainActivity.class));
                        finish();
                        break;
                    case "SIGN"://签到
                        Intent intent=new Intent(MyPointActivity.this, MainActivity.class);
                        intent.putExtra("id",3);
                        intent.putExtra("mainId","3");
                        startActivity(intent);
                        finish();
                        break;
                    case "INVITATION_FRIENDS"://邀请好友
                        startActivity(new Intent(MyPointActivity.this,InvitationActivity.class));
                        finish();
                        break;
                        default:
                            break;
                }
            }
        });
        getPresenter().getBalance();
        getPresenter().getTaskList();
    }

    @NonNull
    @Override
    public MyPointPre createPresenter() {
        return new MyPointPre();
    }

    @OnClick(R.id.tv_record)
    void toRecord() {
        Intent i = new Intent(this, IntegralRecordActivity.class);
        startActivity(i);
    }


    @Override
    public void showTaskList(TaskListBean bean) {
        if (bean.returnCode.equals("0000")) {
            lists.addAll(bean.getReturnData());
            adapter.setData(lists);
        } else {
            Util.toast(this, bean.returnMessage);
        }
    }

    @Override
    public void showTaskBalance(GetBalanceBean bean) {
        if (bean.returnCode.equals("0000")) {
            tv_point.setText(bean.getReturnData()+"");
        } else {
            Util.toast(this, bean.returnMessage);
        }
    }
}
